package com.wjp.villagemp.service.impl.manage;

import com.wjp.villagemp.mapper.manage.CourseMapper;
import com.wjp.villagemp.model.manage.CourseEntity;
import com.wjp.villagemp.service.manage.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Jacob
 * @Date: 2019/1/18 17:27
 * @Description:
 */
@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public List<CourseEntity> listCourse(int pageSize, int start, int courseNum) {
        return courseMapper.listCourse(pageSize, start, courseNum);
    }

    @Override
    public Integer countCourse(int courseNum) {
        return courseMapper.countCourse(courseNum);
    }

    @Override
    public Integer insertCourse(CourseEntity courseEntity) {
        int key = 0;
        try {
            key = courseMapper.insert(courseEntity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return key;
    }

    @Override
    public Integer updateCourse(CourseEntity courseEntity) {
        int key = 0;
        try {
            key = courseMapper.updateByPrimaryKey(courseEntity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return key;
    }

    @Override
    public Integer removeCourse(int courseNum) {
        int key = 0;
        try {
            key = courseMapper.deleteByPrimaryKey(courseNum);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return key;
    }

    @Override
    public List<CourseEntity> listAllCourse() {
        List<CourseEntity> courseEntityList = null;
        try {
            courseEntityList = courseMapper.selectAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return courseEntityList;
    }
}
